import grace from "../../utils/grace.js"
grace.page({
      data: {
            user: {},
            order: {
                  wait_pay: 0,
                  wait_pindan: 0,
                  wait_deliver: 0,
                  wait_receive: 0,
                  completed: 0
            },
            total: { //总价
                  is_auth: false //手否需要绑定手机
            },
            contact_isshow: false,
            tips: {
                  status: 0
            },
            feedback_canUse: false
      },
      onLoad: function(options) {
            this.loadData();
            this.loadOrderStatistics();
            //this.loadTips();

            this.$bus.$on("update_cart_event", (data) => {
                  this.loadOrderStatistics();
            });


            this.$data.feedback_canUse = wx.canIUse('button.open-type.feedback');
      },
      loadTips: function() {
            this.$http.get('/api/home/join_info', {}).then((res) => {
                  this.$data.tips = res;
            })
      },
      onShow() {
            this.$data.contact_isshow = false;
            this.loadData();
            this.loadOrderStatistics();
      },
      loadData: function() {
            this.$http.get('api/user/info', {}).then((res) => {
                  this.$data.user = res;
            })
      },
      loadOrderStatistics: function() {
            this.$http.get('api/order/user_order_statistics', {}).then((res) => {
                  this.$data.order = res;
            })
      },
      openCoupon: function() {
            wx.navigateTo({
                  url: '../my_ticket/my_ticket',
            })
      },
      onPullDownRefresh: function() {
            this.loadData();
            this.loadOrderStatistics();
            //this.loadTips();
      },
      openAddress: function(e) {
            wx.navigateTo({
                  url: '../address/address'
            })
      },
      openTips: function(e) {
            if (this.$data.tips.status) {
                  wx.navigateTo({
                        url: '../adweb/adweb?url=' + this.$data.tips.join_url
                  });
            }
      },
      openRecharge: function() {
            wx.navigateTo({
                  url: '../recharge/recharge'
            })
      },
      openMoneyCharge: function() {
            wx.navigateTo({
                  url: '../uc_money/uc_money'
            })
      },
      openIntegralCharge: function() {
            wx.navigateTo({
                  url: '../uc_integral/uc_integral'
            })
      },
      openContact: function() {
            this.$data.contact_isshow = true;
      },
      openMobile: function(e) {
            wx.makePhoneCall({
                  phoneNumber: '13427790490'
            })
      },
      closeContactDialog: function() {
            this.$data.contact_isshow = false;
      }
})